<?php
namespace Systemht\Model;
use Think\Model;
class ArticleModel extends Model{
	protected $insertField = array('name','cate_id','content','keyword','desc','sort','pv','publish_time','comment','recom','show','renshu','price','ename');
	protected $updateField = array('id','name','cate_id','content','keyword','desc','sort','pv','publish_time','comment','recom','show','renshu','price','ename');
	protected $_validate = array(
		array('name','require','文章标题不能为空'),
		array('cate_id','0','请选择文章分类',1,'notequal'),
		array('content','require','文章内容不能为空'),
		);
	protected function _before_insert(&$data,$option){
		$data['publish_time'] = strtotime(I('post.publish_time'));
		$data['ctime'] = time();
		$data['recom'] = isset($data['recom']) ? $data['recom'] : -1;
		$data['show'] = isset($data['show']) ? $data['show'] : -1;
		if(isset($_FILES['image']) && $_FILES['image']['error'] == 0){
            $data['image'] = uploadImage('image',1);
        }
	}
	protected function _before_update(&$data,$option){
		$data['publish_time'] = strtotime(I('post.publish_time'));
		$data['mtime'] = time();
		$data['recom'] = isset($data['recom']) ? $data['recom'] : -1;
		$data['show'] = isset($data['show']) ? $data['show'] : -1;
		if(isset($_FILES['image']) && $_FILES['image']['error'] == 0){
            $data['image'] = uploadImage('image',1);
            delImage(I('post.old_image'));
        }
	}
}